var g, _extends = Object.assign || function(t) {
  for (var e = 1; e < arguments.length; e++) {
      var a, r = arguments[e];
      for (a in r) Object.prototype.hasOwnProperty.call(r, a) && (t[a] = r[a]);
  }
  return t;
}, _tools = require("../../utils/tools"), app = getApp(), page = app.page, request = app.util.request, route = app.route, toast = app.toast;
page({
  data: {
      cur: 0,
      swiper_margin: 220 / 750 * wx.getSystemInfoSync().screenWidth,
      score: 0,
      identityList: {},
      current: 0,
      agreement: false,
  },
  onLoad: function(t) {
      g = this;
      let userInfo = wx.getStorageSync("userInfo")
      if(userInfo){
        request({
          url: "AddUsersLog",
          data: {
            user_id: userInfo.id,
            url: '/fenxiao/index/index',
            title: "身份升级"
          },
          success: function(a) {
          }
        })
        request({
          url: "DistributorType",
          data: {
            user_id: userInfo.id,
            id: userInfo.identity_id,
          },
          success: function(a) {
            g.setData({
              identityList: a
            })
          }
        })
      }
  },
  onReady: function() {
      var t = wx.getSystemInfoSync().screenWidth, e = .04 * t, t = (e * e + t * t / 4) / (2 * e);
      g.setData({
          style: "background: radial-gradient(circle at 50% " + (e - t) + "px, " + wx.getStorageSync("system").foot_color2 + " " + t + "px, rgba(0,0,0,0) " + t / 2 + "px);"
      }), (0, _tools.getNodeInfo)({
          id: "#top",
          success: function(t) {
              return g.setData({
                  top: t.bottom
              });
          }
      });
  },
  onShow: function() {
      
  },
  onPullDownRefresh: function() {
     
  },
  cardSwiper: function(t) {
      g.setData({
          cur: t.detail.current
      });
  },
  toPage: function(t) {
      var e = t.currentTarget.dataset.url;
      switch (e) {
        case 'upgrade' :
          wx.navigateTo({
            url: "/fenxiao/upgrade/upgrade",
          })
        break;
        default:
          route({
              type: "navigate",
              url: e
          });
      }
  },
  selectGood(e){
    let current = e.currentTarget.dataset.index
     g.setData({
      current
     })
  },
  onAgreement(){
    g.setData({
      agreement: !g.data.agreement
     })
  },
  goAgreement(){
    request({
      url: "DistributorAgreement",
      showLoading: !1,
      data: {},
      success: function(t) {
        app.centent = t.content
        wx.navigateTo({
          url: '/u_pages/html_page/index?title=分销协议',
        })
      }
    })
  },
  submit(){
    if(!g.data.agreement){
      toast("阅读并同意推广大使服务协议");
      return false
    }
    request({
      url: "DistributorOrderPay",
      data: {
        order_id:  g.data.identityList[g.data.current].id,
        user_id: g.data.userInfo.id
      },
      success: function(t) {
          delete t._code
          t.appId ? (0, _tools.wxPay)({
              data: t,
              success: function(t) {
                toast("升级成功");
                request({
                  url: "Openid",
                  showLoading: !1,
                  data: {
                      user_id: g.data.userInfo.id
                  },
                  success: function(t) {
                    g.setData({
                      userInfo: t
                    })
                    wx.redirectTo({
                      url: '/fenxiao/identity/identity',
                    })
                  }
                })
              }
            }) : toast("错误:" + t);
        }
    });
  },
});